<?php 
 class BlogController extends AuthController{
 	private $db;
 	public function __init(){
 		$this->db=new BlogModel;
 	}
 	//显示栏目列表
 	public function index(){	
 		$data=$this->db->getall();
 		$this->assign('data',$data['blog']);
 		$this->assign('page',$data['page']);
 		$this->display('index.html');
 		// P($data);exit;
 		// $this->	
 	}
 	// 添加栏目
 	public function add(){
 		if (IS_POST) {
 			if ($this->db->addBlog()) {
 				$this->success("添加成功",__CONTROLLER__);
 			}else{
 				$this->error($this->db->error);
 			}
 		}else{
 			//获得栏目列表
 			$category=new CategoryModel;
 			$categoryData=$category->getall();
 			$this->assign('categoryData',$categoryData);
 			$this->display('add.html');
 		}
 	}
 	public function edit(){
 		if (IS_POST) {
 			if ($this->db->editBlog()) {
 				$this->success("修改成功",__CONTROLLER__);
 			}else{
 				$this->error($this->db->error);
 			}
 		}else{
 			//读取博客
 			$bid=$_GET['bid'];
 			$field=$this->db->where('bid='.$bid)->find();
 			$category=new CategoryModel;
 			$categoryData=$category->getall();
 			// 当前博客栏目为选中状态
 			foreach ($categoryData as $id => $cat) {
 				$categoryData['id']['selected']=$cat['cid']==$field['cid']?" selected=''":'';}
 				$this->assign('categoryData',$categoryData);
				$this->assign('field',$field);
				$this->display('edit.html');
 		}
 	}
 }


 ?>